package com.question.business.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.question.business.user.entity.UserDept;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户部门Mapper接口
 *
 * @author star
 * @since 2023-09-15
 */
@Mapper
public interface UserDeptMapper extends BaseMapper<UserDept> {

    /**
     * 用户部门查询
     *
     * @param userId 用户ID
     * @return List<String> 响应参数
     */
    @Select("SELECT dept_id FROM t_user_dept WHERE user_id = #{userId}")
    List<String> queryDeptByUserId(String userId);

    /**
     * 部门用户查询
     *
     * @param deptId 部门ID
     * @return List<String> 响应参数
     */
    @Select("SELECT user_id FROM t_user_dept WHERE dept_id = #{deptId}")
    List<String> queryUserByDeptId(String deptId);

    /**
     * 根据用户ID删除部门
     *
     * @param userId 用户ID
     */
    @Delete("DELETE FROM t_user_dept WHERE user_id = #{userId}")
    void deleteByUserId(String userId);

    /**
     * 根据部门ID删除用户
     *
     * @param deptId 部门ID
     */
    @Delete("DELETE FROM t_user_dept WHERE dept_id = #{deptId}")
    void deleteByDeptId(String deptId);

}